package com.gin.kotlin.vegetables_kot.database.converter

import androidx.room.TypeConverter
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime

/**
 * 类型转换器
 */
class MyTypeConverter {
    companion object {
        @TypeConverter
        @JvmStatic
        fun zdtToLong(zdt: ZonedDateTime?): Long? = zdt?.toEpochSecond()

        @TypeConverter
        @JvmStatic
        fun longToZdt(time: Long?): ZonedDateTime? = time?.let { ZonedDateTime.ofInstant(Instant.ofEpochSecond(it), ZoneId.systemDefault()) }

        @TypeConverter
        @JvmStatic
        fun stringListToString(list:List<String>) = list.joinToString ("||")

        @TypeConverter
        @JvmStatic
        fun stringToStringList(string: String) = string.split("||")


    }
}